import 'package:flutter/material.dart';
import 'widgets/help_header.dart';
import 'widgets/help_section.dart';
import 'widgets/help_footer.dart';
import 'widgets/help_data.dart';

class HelpScreen extends StatefulWidget {
  const HelpScreen({Key? key}) : super(key: key);

  @override
  State<HelpScreen> createState() => _HelpScreenState();
}

class _HelpScreenState extends State<HelpScreen> with SingleTickerProviderStateMixin {
  late AnimationController _fadeController;
  late Animation<double> _fadeAnimation;
  final List<bool> _expandedList = List.generate(HelpData.helpItems.length, (index) => index == 0);

  @override
  void initState() {
    super.initState();
    _fadeController = AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 1000),
    );
    _fadeAnimation = CurvedAnimation(
      parent: _fadeController,
      curve: Curves.easeIn,
    );
    _fadeController.forward();
  }

  @override
  void dispose() {
    _fadeController.dispose();
    super.dispose();
  }

  void _updateExpandedStatus(int index, bool isExpanded) {
    setState(() {
      for (int i = 0; i < _expandedList.length; i++) {
        _expandedList[i] = i == index && !isExpanded;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Directionality(
      textDirection: TextDirection.rtl,
      child: Scaffold(
        appBar: AppBar(
          title: const Text(
            'ياردەم',
            style: TextStyle(
              color: Color(0xFFFF8C00),
              fontWeight: FontWeight.bold,
              fontSize: 20,
              shadows: [
                Shadow(
                  offset: Offset(1.0, 1.0),
                  blurRadius: 3.0,
                  color: Color.fromARGB(150, 0, 0, 0),
                ),
              ],
            ),
          ),
          backgroundColor: const Color(0xFF3F5491),
          centerTitle: true,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back),
            onPressed: () => Navigator.of(context).pop(),
          ),
        ),
        body: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                Colors.grey.shade100,
                Colors.white,
              ],
            ),
          ),
          child: FadeTransition(
            opacity: _fadeAnimation,
            child: SingleChildScrollView(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const HelpHeader(),
                  ...List.generate(
                    HelpData.helpItems.length,
                    (index) => HelpSection(
                      title: HelpData.helpItems[index]['title']!,
                      content: HelpData.helpItems[index]['content']!,
                      index: index,
                      isExpanded: _expandedList[index],
                      onExpandChanged: _updateExpandedStatus,
                    ),
                  ),
                  const HelpFooter(),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
} 